package com.fangda.network.websocket;

import com.fangda.network.AbstractNetwork;
import com.fangda.network.NetworkCallback;
import com.fangda.network.NetworkConfig;
import lombok.Getter;
import lombok.Setter;

public abstract class AbstractWebsocketNetwork extends AbstractNetwork {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1960822889422612110L;


    public AbstractWebsocketNetwork(String id, NetworkConfig config) {
        super(id, config);
    }

    @Getter
    @Setter
    private boolean ssl = false;


    public String getUrl() {
        String path = "";
        if(config.getPath() == null || config.getPath().length() == 0) {
            path = "/";
        } else {
            if(config.getPath().startsWith("/")) {
                path = config.getPath();
            } else {
                path = "/" + config.getPath();
            }
        }
        if(ssl) {
            return "wss://" + config.getIp() + ":" + config.getPort() + path;
        } else {
            return "ws://" + config.getIp() + ":" + config.getPort() + path;
        }
    }

}
